import fs from 'fs';
import path from 'path';
import rimraf from 'rimraf'; // 使用 rimraf v3 的默认导出
import webpackPaths from '../configs/webpack.paths';

export default function deleteSourceMaps() {
  const remove = (pattern) => {
    rimraf(pattern, (err) => {
      if (err) console.error(`删除 ${pattern} 失败:`, err);
    });
  };

  if (fs.existsSync(webpackPaths.distMainPath)) {
    const pattern = path.join(webpackPaths.distMainPath, '*.js.map');
    remove(pattern);
  }

  if (fs.existsSync(webpackPaths.distRendererPath)) {
    const pattern = path.join(webpackPaths.distRendererPath, '*.js.map');
    remove(pattern);
  }
}
